package com.hava.demo.springmvc.scheduled;

import com.hava.demo.springmvc.onlyone.entity.OnlyOne;
import com.hava.demo.springmvc.onlyone.service.OnlyOneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;

/**
 * Created by hava on 2015/5/23.
 * Spring Framework下的计划任务，
 */

//以组件的方式进行注入
@Component
public class DemoScheduledTask extends TimerTask {

    @Autowired
    OnlyOneService onlyOneService;

    @Scheduled(cron="0/30 * *  * * ? ")
    @Override
    public void run() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        System.out.println("Class DemoSchueduledTask Method run Debug:run time:" + simpleDateFormat.format(now));
    }
}